package cohesion.scene.draw
{
	import cohesion.io.ResourceCache;
	import cohesion.net.ILoadItem;
	import cohesion.net.LoaderItem;
	import cohesion.net.LoaderLite;
	import cohesion.scene.IScene;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.geom.Point;
	
	import flashx.textLayout.edit.IInteractionEventHandler;
	
	import mx.utils.StringUtil;
	
	
	/**
	 * 
	 * @author 徐俊杰
	 * @date 2012-2-21
	 */
	public class SquareSceneDraw implements ISceneDraw
	{
		/**
		 * 切片宽度 
		 */		
		private var _cutWidth:Number;
		
		/**
		 * 切片高度 
		 */		
		private var _cutHeight:Number;
		
		private var _scene:IScene;
		
		
		public function SquareSceneDraw(scene:IScene)
		{
			_scene = scene;
		}
		
		public function drawCut(cutX:int, cutY:int, cutBitmapData:BitmapData):void
		{
			var cutGlobalP:Point = new Point(cutX * _cutWidth, cutY * _cutHeight);
			var cutDisplayP:Point = _scene.globalToDisplay(cutGlobalP);
			_scene.bitmapData.copyPixels(cutBitmapData, cutBitmapData.rect, cutDisplayP);
		}
		
		public function get cutEndX():int
		{
			return Math.ceil(( _scene.position.x + _scene.width) / _cutWidth);
		}
		
		public function get cutEndY():int
		{
			return Math.ceil(( _scene.position.y + _scene.height) / _cutHeight);
		}
		
		public function get cutStartX():int
		{
			return Math.floor(_scene.position.x / _cutWidth);
		}
		
		public function get cutStartY():int
		{
			return Math.floor(_scene.position.y / _cutHeight);
		}
		
	}
}